package com.xwh.shop.goods.service.controller;

import com.xwh.shop.common.Result;
import com.xwh.shop.goods.model.entity.GoodsImage;
import com.xwh.shop.goods.service.service.GoodsImageService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwh
 * @since 2025-07-16
 */
@Slf4j
@RestController
@RequestMapping("/goodsImage")
public class GoodsImageController {

    @Resource
    private GoodsImageService goodsImageService;

    @Operation(summary = "添加图片")
    @PostMapping("")
    public Result<Object> add(@RequestBody GoodsImage goodsImage){
        goodsImageService.save(goodsImage);
        return Result.success();
    }

    @Operation(summary = "查询图片")
    @GetMapping("/{id}")
    public Result<GoodsImage> findById(@PathVariable Long id){
        GoodsImage goodsImage = goodsImageService.getById(id);
        log.info("找到的图片 goodsImage:{}",goodsImage);
        return Result.success(goodsImage);
    }

    @Operation(summary = "删除图片")
    @DeleteMapping("/id")
    public Result<Object> delete(@PathVariable Long id){
        boolean res = goodsImageService.removeById(id);
        return Result.success(res);
    }
    @Operation(summary = "更新图片")
    @PutMapping("")
    public Result<Object> update(@RequestBody GoodsImage goodsImage){
        log.info("更新商品图片：{}", goodsImage);
        boolean res = goodsImageService.updateById(goodsImage);
        return Result.success(res);
    }


}
